using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;
using System.Collections;

namespace DAOLayer
{
    public class TaiKhoanDao
    {
        public  DataTable LayBangTaiKhoan()
        {
            DataTable dt = new DataTable();
            OleDbConnection cn = new OleDbConnection();
            cn = Database.ConnectionData();
            string strSQL = "select * from TaiKhoan";
            OleDbDataAdapter da = new OleDbDataAdapter(strSQL, cn);
            da.Fill(dt);
            cn.Close();
            return dt;
        }
        public ArrayList LayDanhSachTaiKhoan(DataTable dt)
        {
            ArrayList ds = new ArrayList();
            int i = 0;
            while (i < dt.Rows.Count)
            {
                TaiKhoanDto tk = new TaiKhoanDto();
                tk.MaTaiKhoan = dt.Rows[i]["MaTaiKhoan"].ToString();
                tk.Password = dt.Rows[i]["Password"].ToString();
                tk.PhanQuyen = dt.Rows[i]["PhanQuyen"].ToString();
                ds.Add(tk);
                i++;
            }
            return ds;
        }
        public void CapNhatBangTaiKhoan(DataTable dt)
        {
            OleDbConnection cn = Database.ConnectionData();
            string strSQL = "select * from TaiKhoan";
            OleDbDataAdapter da = new OleDbDataAdapter(strSQL, cn);
            OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
            da.Update(dt);
            cn.Close();
        }

        public void XoaTaiKhoan(int manv)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = Database.ConnectionData();
            string strSQL = "delete from TaiKhoan where MaTaiKhoan=?";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@MaTaiKhoan", OleDbType.Integer);
            cmd.Parameters["@MaTaiKhoan"].Value = manv;
            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
